﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Messaging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.Media3D;
using System.Windows;
using Tookit.Mvvm.Navigation.Message;
using Tookit.Mvvm.Navigation.Views;

namespace Tookit.Mvvm.Navigation.ViewModels
{
    public partial class ShellViewModel : ObservableObject
    {
        private readonly LoginView _loginView;
        private readonly MainWindow _mainWindow;

        // 通过DI注入IWindowService
        public ShellViewModel(MainWindow mainWindow, LoginView loginView)
        {
            _mainWindow = mainWindow;
            _loginView = loginView;

            
            Init();
            RegistMessage();
        }

        private void RegistMessage()
        {
            WeakReferenceMessenger.Default.Register<LoginMessage>(this, (sender, message) =>
            {
                
                WeakReferenceMessenger.Default.Send(new ChangeWindowSizeMessage(1200, 800));
                Body = _mainWindow;

            });

            WeakReferenceMessenger.Default.Register<LoginOutMessage>(this, (sender, message) =>
            {
                WeakReferenceMessenger.Default.Send(new ChangeWindowSizeMessage(600, 450));
                Body = _loginView;

            });
        }

        private void Init()
        {
            Body = _loginView;
        }


        [ObservableProperty]
        private object _body;

    }
}
